/**
 * 
 */
var params={};
$(function(){
	adaptive();
	params={size:2,type:2,content:$('#anno-search-field').val()};
	loadDataPageIetm("/ietm/annotationsN", "srcoll-documentation", "lists",params);
	//注释搜索
	$('#anno-search').click(function(){
		$('#lists').html("");
		params={size:2,type:2,content:$('#anno-search-field').val()};
		loadDataPageIetm("/ietm/annotationsN", "srcoll-documentation", "lists",params);
	});
	
	$('#annotations-export').click(function(e){
		window.location.href="/file/xls/export";
	});
	$('#annotations-upload').click(function(e) {		
	if($('li[class="active"][ownType="rows"]').length==1){
		var id=$('li[class="active"][ownType="rows"]').parent().attr("rowId");
		var diag = new $.Zebra_Dialog({
			source : {
				'iframe' : {
					'id':'annotations-upload-diag',
					'src':'/ietm/annotations/getObject?id='+id+"&page=annotations-upload" ,
					'height' : 300
				}
			},
			width : 600,
			title : '上传附件',
		    buttons:  [
	               {caption: '上传', callback: function() {
	            	   var file=$("#annotations-upload-diag").contents().find("#fileId")
	            	   
	            	   if(file[0].files.length==0)
	            	   {
	            		   $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选择要上传的文件！</div></div>', {
	    			            'title':'提示',
	    			            'buttons':['确定']
	    			         });
	            	        return false;
	            	   
	            		}
	            	   var fileSize = file[0].files[0].size;
	            	   if(fileSize >1048576*5){
	            	        $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">文件不能大于 5M !</div></div>', {
	    			            'title':'提示',
	    			            'buttons':['确定']
	    			         });
	            	        return false;
	            	    }
	            	   $("#annotations-upload-diag").contents().find("#annoations-upload-form").submit();
	            	   $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">上传成功!</div></div>', {
    			            'title':'提示',
    			            'buttons':[{caption: '确定',callback:function(){
    			            	 //window.location.href="/ietm/annotations";
    			            	 loadPage("/ietm/annotations");
    			            }}]
    			         });
    		    	  
	            	  
	                  }}
                    ]
		});
	}else{
		 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一条数据!</div></div>', {
	            'title':'提示',
	            'buttons':['确定']
	         });
	}});
	
	$('#annotations-del-upload').click(function(e) {		
		if($('li[class="active"][ownType="rows"]').length==1){
		var id=$('li[class="active"][ownType="rows"]').parent().attr("rowId");
		 $.ajax({
		     type: "post",
		     dataType: "text",
		     url:'/ietm/annoations/delFile?id='+id,
		     success: function (data, status) {
		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
		    	 //window.location.href="/ietm/annotations?";
		    	 loadPage("/ietm/annotations");
		     },
		     error: function (data) {
		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
		     }
		 });
	}else{
		 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一条数据!</div></div>', {
	            'title':'提示',
	            'buttons':['确定']
	         });
	}});
	
	
	
	//注释编辑
	$('#annotations-edit').click(function(e) {		
		if($('li[class="active"][ownType="rows"]').length==1){
		var id=$('li[class="active"][ownType="rows"]').parent().attr("rowId");
		loadPage('/ietm/annotations/getObject?id='+id+"&page=annotations-edit&"+new Date());
	}else{
		 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一条数据!</div></div>', {
	            'title':'提示',
	            'buttons':['确定']
	         });
	}});
	
	$('#annotations-del').on('click', function(e) {
		var  ids="";
		$('li[class="active"][ownType="rows"]').each(function(){
			ids += $(this).parent().attr("rowId")+",";
		});
		ids=ids.substring(0,ids.length-1);
		   
		 $.ajax({
	     type: "post",
	     url:"/ietm/commentTags/deleteIds" ,
	     data:{ids:ids},
	     success: function (data, status) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	    	 loadPage(encodeURI("/ietm/annotations?content="+$('#anno-search-field').val()));
	     },
	     error: function (data) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	     }
	 });
		   
	 });
	
	
});
//构建数据列表--用于分页查询
function dataKk(data, me) {
	data=data.rows;
	var result = '';
	var arrLen = data.length;
	if (arrLen > 0) {
		for (var i = 0; i < arrLen; i++) {
			var visibility=data[i].visibility==="0"?"共享":"私有";
			result +='<a dmId="'+data[i].dmodelId+'" rowId="'+data[i].id+'" projectId="'+data[i].projectId+'" onclick="dw(this)">'
					+'<li ownType="rows">'
					+'<div class="spare-new clearfix">'
					+'<div>数据模块编码：'+data[i].code+'</div></div>'
					
					+'<div class="spare-new clearfix">'
					+'<div>标题：'+data[i].title+'</div></div>'
					+'<div class="spare-new clearfix">'
					+'<div class="spare-newl">内容：'+data[i].content+'</div>'
					+'<div class="spare-newl">可见方式：'+visibility+'</div></div>'
					+'<div class="spare-new clearfix">'
					+'<div class="spare-newl">所属用户：'+data[i].userName+'</div>'
					+'<div class="spare-newl">附件：<object><a style="color:#0000FF" href="'+data[i].file+'">'+data[i].file+'</a></object></div></div>'
					+'<div class="paper-c">日期：'+data[i].publishDate+'</div>'
					+'<div class="documentation-check"></div></li></a>';
		}
	} else {
		me.lock();
		me.noData();
	}
	return result;
}
function saveAnnotations(){
	$("#editForm").submit(); 
}
//
function dw(p){
	var params={
            dmId:$(p).attr("dmId"),
            projectId:$(p).attr("projectId"),
            type:"comment"
        };
	httpPost("/ietm/goDmUrl", params);
}